import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-01-27
 * Time: 15:25
 */
public class practice {

    //9. 获取一个数二进制序列中所有的偶数位和奇数位，分别输出二进制序列。
    public static void main(String[] args) {
        Random rand = new Random();
        int n = rand.nextInt(10001);
        System.out.println(n);

        //偶数位
        for (int i = 31; i >= 1; i -= 2) {
            System.out.print((n >> i) & 1);
        }
        System.out.println(" ");
        //奇数位
        for (int j = 30; j >= 0; j -= 2) {
            System.out.print((n >> j) & 1);
        }
    }


    //8. 写一个函数返回参数二进制中 1 的个数
    public static void main8(String[] args) {
        Random rand = new Random();
        int n = rand.nextInt(1001);
        System.out.println(n);
        int count = 0;
        while (n != 0) {
            if (n % 2 == 1) {
                count++;
            }
            n /= 2;
        }
        System.out.println(count);
    }

    /*
    7. 求出0～999之间的所有“水仙花数”并输出。(“水仙花数”是指一个三位数，其各位数字的立方和确好等于该数
    本身，如： 153＝1^3＋5^3＋3^3 ，则153是一个“水仙花数”。)
    */

    public static void main7(String[] args) {
        for (int i = 100; i <= 999; i++) {
            int b = i;
            int sum = 0;
            while (b != 0) {
                int c = b % 10;
                if (c != 0) {
                    sum += Math.pow(c, 3);
                } else {
                    sum += 0;
                }
                b /= 10;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }
    }

    //6. 求两个正整数的最大公约数
    public static void main6(String[] args) {
        Random rand = new Random();
        int m = rand.nextInt(101);
        int n = rand.nextInt(101);
        System.out.println(n);
        System.out.println(m);

        while (n % 2 == 0 && m % 2 == 0) {
            m /= 2;
            n /= 2;
        }
        while (m != n) {
            if (m > n) {
                m = m - n;
            } else {
                n = n - m;
            }
        }
        System.out.println(m);
    }

    //5. 输出乘法口诀表
    public static void main5(String[] args) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.println(i + "*" + j + "=" + (i * j));
            }
        }
    }

    //4. 输出 1000 - 2000 之间所有的闰年
    public static void main4(String[] args) {
        for (int i = 1000; i <= 2000; i++) {
            if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
                System.out.println(i);
            }
        }
    }


    //3. 打印 1 - 100 之间所有的素数
    public static void main3(String[] args) {
        for (int i = 2; i <= 100; i++) {
            int change = 0;
            for (int j = 2; j < i; j++) {
                change = 1;
                if (i % j == 0) {
                    change = 0;
                    break;
                }
            }
            if (change == 1 || i == 2) {
                System.out.println(i);
            }
        }
    }


    // 2.判定一个数字是否是素数
    public static void main2(String[] args) {
        Random rand = new Random();
        int n = rand.nextInt(101);
        System.out.println(n);
        int change = 0;

        if (n == 1) {
            System.out.println("不是素数");
        }

        for (int i = 2; i < n; i++) {
            change = 1;
            if (n % i == 0) {
                System.out.println("不是素数");
                change = 0;
                break;
            }
        }
        if (change == 1) {
            System.out.println("是素数");
        }
    }

    //1. 根据年龄, 来打印出当前年龄的人是少年(低于18), 青年(19-28), 中年(29-55), 老年(56以上)
    public static void main1(String[] args) {
        Random rand = new Random();
        int n = rand.nextInt(101);
        System.out.println(n);

        if (n <= 18) {
            System.out.println("少年");
        } else if (n <= 28) {
            System.out.println("青年");
        } else if (n <= 55) {
            System.out.println("中年");
        } else {
            System.out.println("老年");
        }
    }
}

